/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    // var addMore = $.Params.create();
    // var arrData = [{ "judgeOpenId": "324324", "playerId": "480F1FDB759949008D82EDAD19FD375F", "meetNum": "1001", "questionId": "412190C0-EB42-4909-8E84-4D3E0F9889C3", "checkId": "0F8A6344-8443-41B3-99C5-C09FCC2F2DCE", "score": 14 }, { "judgeOpenId": "324324", "playerId": "480F1FDB759949008D82EDAD19FD375F", "meetNum": "1001", "questionId": "412190C0-EB42-4909-8E84-4D3E0F9889C3", "checkId": "37FEDEDD-0E67-488E-9E40-42B6F1C444EB", "score": "15" }];
    // var params = JSON.stringify(arrData);
    // addMore.addParams("params", params);
    // addMore.addParams("totalScore", 29);
    // addMore.addParams("hospitalName", "评委2医院");
    // addMore.ajax("get", "http://192.168.1.10:5000/api/v2.0/wx/pfLog", function (data) {
    //     alert(JSON.stringify(data));
    // })
    var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);

    getData();

    //查询
    $("#searchBtn").on("click", function () {
        var title = $("#title").val();
        var meetNum = $("#meetNum").val();
        if (title != "") {
            sel.addParams("title", title);
        } else {
            sel.addParams("title", undefined);
        }
        if (meetNum != "") {
            sel.addParams("meetNum", meetNum);
        } else {
            sel.addParams("meetNum", undefined);
        }

        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addDataBtn').on("click", function () {
        window.location.href = "pfMeetAdd.html";
    });

    //删除事件
    $('#delBtn').on("click", function () {
        var params = getCheckData();
        if (params != "") {
            if (confirm("确定要删除吗！")) {
                var del = $.Params.create();
                //del.addParams("params", params)
                del.ajax("delete", getAdminIP() + "pfMeets?params=" + params, function (data) {
                    if (data.success) {
                        alert("删除成功！");
                        getData();
                    }
                })
            }
        } else {
            alert("请至少选中一项");
        }
    });

    //获取数据
    function getData() {
        getPageData("get", sel, getAdminIP() + "pfMeets", function (data) {
            if (data.success) {
                var html = "";
                if (data.total > 0) {
                    $.each(data.result, function (i, val) {
                        var isReg = "";
                        html += "<tr role='row'' class='even'>" +
                            "<td><input eid='" + val.id + "' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td class='sorting_1'>" + val.title + "</td>" +
                            "<td>" + val.meetTime + "</td>" +
                            "<td>" + val.meetNum + "</td>" +
                            "<td>" + val.lead + "</td>" +
                            "<td>" + val.hourRecord + "</td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='getQuestionInfo(\"" + val.meetNum + "\")'>查看问题</button></td>" +
                            "<td><a href = '" + getIP() + "pfMeet/pfMemberJudgeList.html?meetNum=" + val.meetNum + "&type=1'>查看评委</a></td>" +
                            "<td><a href = '" + getIP() + "pfMeet/pfMemberPlayerList.html?meetNum=" + val.meetNum + "&type=2'>查看选手</a></td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\"" + val.id + "\")'>修改</button></td>" +
                            "</tr>";
                    });

                } else {
                    html = "<tr><td>暂无数据</td></tr>"
                }
                $("#listContainer").html(html);

            }
        })
    }
});
function updateInfo(eid) {
    window.location.href = "pfMeetUpdate.html?eid=" + eid;
}
function getQuestionInfo(meetNum) {
    window.location.href = "pfQuestionList.html?meetNum=" + meetNum;
}
